
package es.udc.emarketapp.http.view.actionForms;

import es.udc.fbellas.j2ee.util.struts.action.PropertyValidator;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;


public class BuyProductForm extends ActionForm {

	private Long idProd;
	private String quantity;
	private Long quantityAsLong;
	
	public BuyProductForm() {
		reset();
	}

	public Long getIdProd() {
		return idProd;
	}

	public void setIdProd(Long idProd) {
		this.idProd = idProd;
	}
	
	public String getQuantity() {
		return quantity;
	}

	public void setQuantity(String quantity) {
		this.quantity = quantity.trim();
	}

	public Long getQuantityAsLong() {
		return quantityAsLong;
	}

	public void reset(ActionMapping mapping, HttpServletRequest request) {
        reset();
    }

	public ActionErrors validate(ActionMapping mapping, 
			HttpServletRequest request) {
		
		ActionErrors errors = new ActionErrors();
		
		quantityAsLong = PropertyValidator.validateLong(errors, "quantity",
				quantity, true, 1, new Long(100));
		
		return errors;
	}
	
	private void reset() {
		idProd = null;
		quantity = null;
		quantityAsLong = new Long(0);
    }
}
